package com.wondersgroup.fjzlpt.console.controller.view.yljgry;

import com.alibaba.fastjson.JSONObject;
import com.wondersgroup.fjzlpt.console.service.inter.yljgry.YljgryService;
import com.wondersgroup.fjzlpt.console.utils.ControllerCommonUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Controller
@RequestMapping("yljgry")
public class YljgryController {

	@Autowired
	private YljgryService yljgryService;

	@RequestMapping("/index.html")
	public String index_yljgxx(HttpServletRequest request)
	{
		JSONObject requestData = ControllerCommonUtils.getRequestData(request);
		request.setAttribute("requestData", requestData);
		return "yljgry/index";
	}
	
	@RequestMapping("/manager.html")
	public String manager_yljgry(HttpServletRequest request)
	{
		String userId = request.getParameter("USERID");
		if(!StringUtils.isEmpty(userId)){
			JSONObject managerYljgryxx = this.yljgryService.queryYljgryxx(userId);
			request.setAttribute("managerYljgryxx", managerYljgryxx);
		}
		JSONObject requestData = ControllerCommonUtils.getRequestData(request);
		request.setAttribute("requestData", requestData);
		return "yljgry/manager";
	}

	@RequestMapping("/receiveRyzp")
	public void receiveRyzp(HttpServletResponse response, @RequestParam("id") String id){
		response.reset();
		response.setContentType("application/x-msdownload;charset=UTF-8");
		OutputStream out = null;
		try{
			out = response.getOutputStream();
			byte[] content = yljgryService.receiveImage(id);
			out.write(content);
		}
		catch (Exception e){
			e.printStackTrace();
		}
		finally{
			try {
				if(out != null){
					out.flush();
					out.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 编辑执业信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/editZyjg.html")
	public String editZyjg(HttpServletRequest request)
	{
		return "yljgry/editZyjg";
	}
}
